#!/bin/bash
#Utility for setting up GTK3/GTK4 window decorations for the Trick or Treat theme
#By ratsrats
FILE="$HOME/.config/gtk-3.0/colors.css"
if [[ -f "$FILE" ]]; then
while IFS= read -r line
do
i=$(($i+1))
theme_colors[$i]=`echo "$line" | sed s/.*#/#/ | sed s/\;//`
echo ${theme_colors[$i]}
done < $FILE
else
cp $HOME/.themes/trick-or-treat/gtk.css $HOME/.config/gtk-3.0/gtk.css
cp $HOME/.themes/trick-or-treat/gtk4.css $HOME/.config/gtk-4.0/gtk.css
ln -s $HOME/.themes/trick-or-treat/asset/ $HOME/.config/gtk-3.0/asset
ln -s $HOME/.themes/trick-or-treat/asset/ $HOME/.config/gtk-4.0/asset
fi
theme_colors_new=`yad --form --title "GTK window decoration configuration tool" --text "Copy your current GTK theme's element colors here" --field="Background (default)":CLR --field="Background (backdrop)":CLR --field="Background (disabled)":CLR --field="Selected (default)":CLR --field="Selected (hover)":CLR --field="Selected (backdrop)":CLR --field="Selected (backdrop+hover)":CLR --field="Selected (disabled)":CLR ${theme_colors[2]} ${theme_colors[3]} ${theme_colors[4]} ${theme_colors[5]} ${theme_colors[6]} ${theme_colors[7]} ${theme_colors[8]} ${theme_colors[9]}`
if [[ $theme_colors_new!="" ]]; then
echo "" > $FILE
for i in {1..8}
do
theme_colors_new=`echo $theme_colors_new | sed s/\|//`
current=`echo $theme_colors_new | cut -c $((1+(7*($i-1))))-$((7+(7*($i-1))))`
cat $HOME/.themes/trick-or-treat/colors.css | grep $i | sed s/$i/$current/ >> $FILE
cat $HOME/.themes/trick-or-treat/colors.css | grep $i | sed s/$i/$current/ >> $HOME/.config/gtk-4.0/colors.css
done
fi